package com.manager.service.impl;

import com.manager.bean.Account;
import com.manager.bean.AccountExample;
import com.manager.bean.PageInfo;
import com.manager.mapper.AccountMapper;
import com.manager.service.AccountService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Account)表服务实现类
 *
 * @author makejava
 * @since 2021-03-02 11:00:19
 */
@Service("accountService")
public class AccountServiceImpl implements AccountService {
    @Resource
    private AccountMapper accountDao;

    @Override
    public PageInfo<Account> findPageInfo(Integer studentId, Integer dormitoryId, Integer pageIndex, Integer pageSize) {
        return null;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param account 主键
     * @return 实例对象
     */
    @Override
    public Account queryById(Integer account) {
        return this.accountDao.selectByPrimaryKey(account);
    }


    @Override
    public List<Account>  getAll(){
        AccountExample accountExample = new AccountExample();
        AccountExample.Criteria criteria = accountExample.createCriteria();
        return accountDao.selectByExample(accountExample);
    }

    /**
     * 新增数据
     *
     * @param account 实例对象
     * @return 实例对象
     */
    @Override
    public Account insert(Account account) {
        this.accountDao.insert(account);
        return account;
    }

    /**
     * 修改数据
     *
     * @param account 实例对象
     * @return 实例对象
     */
    @Override
    public Account update(Account account) {
        this.accountDao.updateByPrimaryKey(account);
        return this.queryById(account.getAccount());
    }

    /**
     * 通过主键删除数据
     *
     * @param account 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer account) {
        return this.accountDao.deleteByPrimaryKey(account) > 0;
    }
}
